package com.haozhen.hbase.process;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Durability;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
import org.apache.hadoop.hbase.coprocessor.ObserverContext;
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
import org.apache.hadoop.hbase.regionserver.wal.WALEdit;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

/**
 * @author haozhen
 * @email haozh@ync1.com
 * @date 2020/10/24  15:03
 */
public class MyFirstProcess extends BaseRegionObserver {

    @Override
    public void prePut(ObserverContext<RegionCoprocessorEnvironment> e, Put put, WALEdit edit, Durability durability) throws IOException {
//        super.prePut(e, put, edit, durability);

        final HTableInterface t2 =  e.getEnvironment().getTable(TableName.valueOf("table2"));

//        byte[] row = put.getRow();

        Cell cell = put.get(Bytes.toBytes("info"), Bytes.toBytes("name")).get(0);


        Put put1 = new Put(put.getRow());

        put1.add(cell);

        t2.put(put1);

        t2.close();
    }
}
